package cn.yyljlyy.blog.admin.service.impl;

import cn.yyljlyy.blog.admin.dao.PermissionDao;
import cn.yyljlyy.blog.admin.entity.Permission;
import cn.yyljlyy.blog.admin.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @function: cn.yyljlyy.blog.admin.service.impl
 * @author: LiJian
 * @data: 2016年11月22日19：04.
 */
@Service
public class PermissionServiceImpl implements PermissionService{

    @Autowired
    private PermissionDao permissionDao;

    @Override
    public List<Permission> findAll() {
        List<Permission> f = permissionDao.findAllByTypeOrderByPidSortingAsc("F");
        List<Permission> Newperms = new ArrayList<>();
        for (Permission permissionBean : f) {
            List<Permission> children = new ArrayList<>();
            for (Permission bean : f) {
                if (bean.getPid() == permissionBean.getId()){
                    children.add(bean);
                }
            }
            permissionBean.setChildren(children);
            if (permissionBean.getChildren().size()>0){
                Newperms.add(permissionBean);
            }
        }
        return Newperms;
    }
}
